<template>
  <div class="mybody">
    <!-- 文章内容开始 -->
    <div class="content">
      <div class="article" v-if="s">
        <h2>{{neirong.title}}</h2>
        <p v-html="neirong.content"></p>
      </div>
    </div>
    <!-- 文章内容结束 -->
    <!-- 页面中固定位置开始 -->
    <div class="fixed">
      <!-- 文章头部开始 -->
      <div class="header">
        <span class="headLeft">
          <i>
            <a href="#">&lt;&lt;{{title.title}}&gt;&gt;</a>
          </i>
          <em>- {{neirong.title}}</em>
        </span>
      </div>
      <!-- 文章头部结束 -->
      <!-- 左侧内容开始 章节列表 -->
      <div class="listLeft" @click="show">
        <s class="read_s"></s>
        <em>目录</em>
      </div>
      <div class="conList" :style="{display:(page? 'block':'none')}">
        <s class="read_s close01" @click="close" :style="{display:(page? 'block':'none')}"></s>
        <ul>
          <li v-for="(p, i) of chapter" :key="i">
            <!-- <router-link :data-num='i' :to="`/read?cid=${p.cid}&bid=${bid}`">{{p.title}}</！router-link> -->
            <div :data-num="i" @click="get">{{p.title}}</div>
          </li>

          <p class="jzzj">
            <a>加载更多章节</a>
          </p>
        </ul>
      </div>
      <!-- 左侧内容开始 -->
      <!-- 右侧内容开始 -->
      <!-- 二维码 -->
      <div class="conRightTop">
        <!--<img src="static/images/read/adv.gif" alt="下载" class="adv">-->
        <div class="text">
          <p class="big">阅读本书，两步就够了......</p>
          <p class="little">
            <span>第一步：</span>下载掌阅iReader客户端
          </p>
          <img
            src="../assets/index (1).png"
            alt="扫一扫"
            class="readEwm"
            style="height: 100px"
            noerror="1"
          />
          <p class="little littlePaddingLeft">
            <span>第二步：</span>用掌阅客户端扫描二维码
          </p>
          <img
            src="../assets/index.png"
            alt="扫一扫"
            class="readEwm"
            style="height: 100px"
            noerror="1"
          />
          <p class="scan">
            <a
              href="//www.ireader.com.cn/index.php?ca=bookdetail.HelpScan&amp;pca=Chapter.Index"
              target="_blank"
            >不知道如何扫描？</a>
          </p>
        </div>
      </div>
      <!-- 换章按钮开始 -->
      <div class="chapter">
        <span title="上一章" btn="chapter" @click="prev(cid)">
          <s class="read_s up"></s>
        </span>

        <span title="下一章" btn="chapter" act="next" @click="next(cid)">
          <s class="read_s down"></s>
        </span>

        <span title="返回顶部" class="go_top" style="display: none; left: 696px" id="btn_back_top">
          <s class="read_s"></s>
        </span>
      </div>
    </div>
  </div>
</template>


<script>
export default {
  data() {
    return {
      page: false,
      chapter: [],
      neirong: [],
      index: 0,
      s: false,
      num: 0,
      bid: 0,
      cid: "",
      title:{}
    };
  },
  methods: {
    show() {
      this.page = !this.page;
    },
    close() {
      this.page = !this.page;
    },
    get(e) {
      // console.log(this.cid)
      this.num = e.target.dataset.num;
      this.neirong = this.chapter[this.num];
      this.close();
      //  this.axios.get("/read/cid",{params:{'num':e.target.dataset.num,'bid':this.cid}}).then((result) => {
      // console.log(result.data);
      // this.neirong=result.data[0];
      // this.close();
      //   })
      
    },
    prev(cid) {
      if (this.num > 0) {
        this.num -= 1;
        this.neirong = this.chapter[this.num];
        // this.$router.push({
        //   query: merge(this.$route.query, { cid: this.num }),
        // });
      }
      //this.$router.push({name:'testDemo',params:{setid:111222}});
    },
    next(cid) {
      console.log(this.chapter.length)
      if (this.num < this.chapter.length) {
        this.num += 1;
        // console.log(this.num)
        this.neirong = this.chapter[this.num];
        // console.log(this.neirong)
        // this.$router.replace({
        //   query: merge(this.$route.query, {
        //     cid: this.num,
            
        //   }),
        //});
      }
    },
  },
  mounted() {
    // 文章内容
    let bid = this.$route.query.bid;
    this.num = parseInt(this.$route.query.cid);
    // this.cid = bid;
    //console.log(this.cid)
    this.axios.get(`/read?bid=${bid}`).then((result) => {
      console.log(result.data);
      this.chapter = result.data;
      this.neirong = result.data[this.num];
      //console.log(this.neirong)
      this.s = true;
    });

    // 文章标题
    let tid = this.$route.query.bid;
    this.axios.get(`/read/title?bid=${tid}`).then((result)=>{
      console.log(result.data);
      this.title = result.data[0];
    });
  },
}
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.mybody {
  background: #e3d1bd;
  height: 100%;
  color: #333;
  font: 14px/20px "Microsoft Yahei", arial, sans-serif;
  display: block;
}
.content {
  width: 750px;
  height: 100%;
  background: #f8f0e7;
  margin: 0 auto;
  box-shadow: 0 0 6px #ccc1b6;
  padding: 0 50px;
}
.article {
  width: 650px;
  overflow: hidden;
  padding-bottom: 100px;
  font-size: 16px;
  letter-spacing: 2px;
}
.article h2 {
  width: 650px;
  padding: 116px 0 50px 0;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
}
.article P {
  text-indent: 2em;
  padding-bottom: 16px;
  line-height: 35px;
}
.fixed {
  width: 750px;
  box-shadow: 0 0 6px #ccc1b6;
  position: fixed;
  left: 50%;
  top: 0;
  margin-left: -375px;
  text-align: center;
}
.header {
  width: 650px;
  height: 65px;
  border-bottom: 1px solid #c7c7c7;
  background: #f8f0e7;
  position: absolute;
  left: 50px;
  top: 0;
  overflow: hidden;
}
.header .headLeft {
  float: left;
  color: #db4e44;
  padding-top: 42px;
}
.header .headLeft a {
  color: #db4e44;
}
.header .headLeft i {
  color: #db4e44;
  font-style: normal;
  float: left;
  max-width: 380px;
}

/* a */
em,
span {
  display: inline-block;
}
.header .headLeft em {
  color: #999;
  float: left;
  max-width: 200px;
}
.listLeft {
  width: 48px;
  background: #eedfd0;
  box-shadow: 0px 0px 6px #ccc1b6;
  position: absolute;
  left: -50px;
  top: 66px;
  cursor: pointer;
}
.read_s {
  width: 24px;
  height: 17px;
  float: left;
  margin: 6px 0 0 12px;
  background: url(../../src/assets/icon.png);
  }
.listLeft em {
  float: left;
  margin: 5px 0 0 10px;
}
.conList {
  width: 640px;
  padding: 30px 0 0 0;
  background: #fff;
  position: absolute;
  left: 0px;
  top: 66px;
  display: none;
}
.conList s {
  width: 16px;
  height: 16px;
  background-position: 26px -18px;
  float: right;
  margin: -25px 5px 0 0;
  cursor: pointer;
}
.read_s {
  width: 24px;
  height: 17px;
  float: left;
  margin: 6px 0 0 12px;
  background: url(../../src/assets/icon.png);
}
.conList ul {
  width: 640px;
  height: 400px;
  overflow: hidden;
  overflow-y: auto;
}
.conList li {
  float: left;
  width: 250px;
  height: 39px;
  line-height: 39px;
  border-bottom: 1px dashed #e2e2e2;
  margin: 0 20px 0 40px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: left;
}

.jzzj {
  width: 640px;
  padding: 30px 0 30px 0;
  text-align: center;
  float: left;
}
.conRightTop {
  height: 230px;
  position: absolute;
  top: 36px;
  right: -236px;
  text-align: left;
}
.conRightTop .text .little,
.ButtonBuyTan .little {
  font-size: 12px;
  padding: 14px 0 10px 0;
}
.conRightTop .text .little span {
  color: #db4e44;
}
.chapter {
  position: fixed;
  left: 50%;
  bottom: 0;
  margin-left: 377px;
}
.chapter span {
  display: block;
  width: 26px;
  height: 64px;
  line-height: 64px;
  text-align: center;
  background: #eedfd0;
  box-shadow: 0px 0px 6px #ccc1b6;
  margin-bottom: 3px;
  cursor: pointer;
}
.chapter span .up {
  background-position: -24px -40px;
  margin: 28px 5px 5px 6px;
}
.chapter span s {
  width: 14px;
  height: 7px;
}
/* s */

.chapter span .down {
  background-position: -24px -56px;
  margin: 28px 5px 5px 6px;
}
.chapter .go_top {
  height: 40px;
  line-height: 40px;
}
.chapter .go_top s {
  width: 12px;
  height: 12px;
  background-position: -24px -35px;
  margin: 13px 5px 5px 6px;
}
</style>